package com.life.goal.infrastructure.english.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.life.goal.domain.entity.OralSentence;
import com.life.goal.domain.entity.WordBook;
import com.life.goal.domain.support.EnglishDataRepository;
import com.life.goal.infrastructure.english.converter.EnglishDataConverter;
import com.life.goal.infrastructure.english.mapper.OralSentenceMapper;
import com.life.goal.infrastructure.english.mapper.WordBookMapper;
import com.life.goal.infrastructure.english.po.OralSentencePO;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class EnglishDataRepositoryImpl implements EnglishDataRepository {

    @Resource
    private WordBookMapper wordBookMapper;
    @Resource
    private OralSentenceMapper oralSentenceMapper;

    @Override
    public void saveWord(WordBook wordBook) {
        wordBookMapper.insert(EnglishDataConverter.INSTANCE.toWordBookPO(wordBook));
    }

    @Override
    public void saveWordBatch(List<WordBook> list) {
        wordBookMapper.insertBatchSomeColumn(EnglishDataConverter.INSTANCE.toWordBookPOList(list));
    }

    @Override
    public void saveOral(OralSentence oralSentence) {
        oralSentenceMapper.insert(EnglishDataConverter.INSTANCE.toOralSentencePO(oralSentence));
    }

    @Override
    public void saveOralBatch(List<OralSentence> list) {
        oralSentenceMapper.insertBatchSomeColumn(EnglishDataConverter.INSTANCE.toOralSentencePOList(list));
    }

    @Override
    public List<OralSentence> queryAllOralSentences() {
        QueryWrapper<OralSentencePO> wrapper = new QueryWrapper<>();
        List<OralSentencePO> result = oralSentenceMapper.selectList(wrapper);
        return EnglishDataConverter.INSTANCE.toOralSentenceList(result);
    }
}
